#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->comboBox->addItems(mSerial.findPort());
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_2_clicked()
{
    ui->pushButton_2->setEnabled(0);
    QTimer::singleShot(500,this,[=]{
        ui->pushButton_2->setEnabled(1);
    });

    ui->comboBox->clear();
    ui->comboBox->addItems(mSerial.findPort());
}

void MainWindow::on_pushButton_clicked()
{
    if(!mSerial.isOpen())
    {
        QString portName = ui->comboBox->currentText();
        quint64 baudSpeed = ui->comboBox_2->currentText().toUInt();
        if(mSerial.open(portName,baudSpeed))
            ui->pushButton->setText("关闭");
    }
    else
    {
        mSerial.close();
        if(!mSerial.isOpen())
            ui->pushButton->setText("打开");
    }
}
